import request, { request as requestMethods } from '@/utils/request';

// 获取用户信息
export const getUserInfo = () => {
    return requestMethods.get('/api/user/info');
};

// 更新用户信息
export const updateUserInfo = (data) => {
    return requestMethods.put('/api/user/info', data);
};

// 修改密码
export const changePassword = (data) => {
    return requestMethods.put('/api/user/password', data);
};

// 上传头像
export const uploadAvatar = (filePath) => {
    return new Promise((resolve, reject) => {
        const baseURL = 'http://localhost:8080';
        uni.uploadFile({
            url: `${baseURL}/api/user/avatar`,
            filePath: filePath,
            name: 'file',
            header: {
                'Authorization': `Bearer ${uni.getStorageSync('token')}`
            },
            success: (res) => {
                const data = JSON.parse(res.data);
                if (data.code === 200) {
                    resolve(data.data);
                } else {
                    reject(data);
                }
            },
            fail: (error) => {
                reject(error);
            }
        });
    });
}; 